package com.jinly.ryder.log.web;

import com.jinly.ryder.common.auth.annotation.Auth;
import com.jinly.ryder.common.auth.model.AuthRole;
import com.jinly.ryder.common.auth.model.AuthType;
import com.jinly.ryder.log.service.LogInstallService;
import com.jinly.ryder.manage.service.AppInstanceService;
import com.jinly.ryder.manage.service.model.AppInstance;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("log/install")
@RequiredArgsConstructor
public class LogInstallController {

    private final AppInstanceService appInstanceService;
    private final LogInstallService logInstallService;

    @GetMapping("installLogListener")
    @Auth(type = AuthType.MANAGE, role = AuthRole.ADMIN, value = "app")
    public void installLogListener(Integer appInstanceId) {
        AppInstance appInstance = appInstanceService.get(appInstanceId);
        if (appInstance != null) {
            logInstallService.installLogListener(appInstance.getHost());
        }
    }
}
